package com.pe1n.yangtaopai.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.pe1n.yangtaopai.R;
import com.pe1n.yangtaopai.bean.IntemOneListBean;
import com.pe1n.yangtaopai.bean.ProdsBean;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/25.
 */

public class MyActivityItemOneRecyclerAdapter extends RecyclerView.Adapter<MyActivityItemOneRecyclerAdapter.MyViewHolder1> {
    private Context mContent;
    private List<IntemOneListBean.DataBean.ItemsBean> itembean;

    public MyActivityItemOneRecyclerAdapter(Context mContent, List<IntemOneListBean.DataBean.ItemsBean> itembean) {
        this.mContent = mContent;
        this.itembean = itembean;
    }

    @Override
    public int getItemCount() {
        return itembean.size();
    }


    @Override
    public MyActivityItemOneRecyclerAdapter.MyViewHolder1 onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContent).inflate(R.layout.activity_item_item_one_layout, parent, false);

        return new MyViewHolder1(view);
    }

    @Override
    public void onBindViewHolder(MyActivityItemOneRecyclerAdapter.MyViewHolder1 holder, int position) {
        holder.restaData(itembean.get(position).getProds());

    }

    class MyViewHolder1 extends RecyclerView.ViewHolder {
        private XRecyclerView xRecyclerView;
        private List<ProdsBean> intemOneListBeen = new ArrayList<>();

        public void restaData(List<ProdsBean> b) {
            intemOneListBeen.clear();
            intemOneListBeen.addAll(b);
            xRecyclerView.getAdapter().notifyDataSetChanged();
        }

        public MyViewHolder1(View itemView) {
            super(itemView);
            xRecyclerView = (XRecyclerView) itemView.findViewById(R.id.xrecyclerview_item_item_one);
            xRecyclerView.setLayoutManager(new GridLayoutManager(mContent, 2, OrientationHelper.VERTICAL, false));
            MyActivityItenOneItemRecyclerAdapter m = new MyActivityItenOneItemRecyclerAdapter(mContent, intemOneListBeen);
            xRecyclerView.setAdapter(m);
        }
    }

}
